package com.fhuc.utils;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * ��ס�û���������
 * @author zjj
 *
 */
public class Sharepf
{
	private static final String TYPE_USER_ID = "1";

	private static final String spfName = "user";
	private SharedPreferences sp;
	private Context context;

	public Sharepf(Context context)
	{
		super();
		this.context = context;
		sp = context.getSharedPreferences(spfName, context.MODE_PRIVATE);
	}

	/**
	 * �����û�������
	 * 
	 * @param name
	 * @param password
	 */
	public void writeUser(String name, String password)
	{// �������?
		SharedPreferences.Editor editor = sp.edit();
		editor.putString("name", name);
		editor.putString("password", password);
		editor.commit();// д���ļ�
	}

	/**
	 * ��ȡ�û�������
	 * 
	 * @return name password
	 */
	public Map<String, String> readUser()
	{
		// ��������map���ض�ȡ�������?
		Map<String, String> map = new HashMap<String, String>();
		map.put("name", sp.getString("name", ""));// �����city��key������Ĳ�����û�ҵ���ʱ�򷵻ص��?
		map.put("password", sp.getString("password", ""));
		return map;
	}

	/**
	 * ��ȡֻ��һ��String��ݵķ���?
	 */
	public String getOnlyOneString(String type)
	{
		String str = sp.getString(type, "");
		return str;

	}

	/**
	 * д���ס����״�?
	 * 
	 * @param flag
	 */
	public void writeRememberPassword(boolean flag)
	{
		SharedPreferences.Editor editer = sp.edit();
		editer.putBoolean("rememberPassword", flag);
		editer.commit();
	}

	/**
	 * �õ���ס����״̬
	 * 
	 * @return
	 */
	public boolean readRememberPassword()
	{
		boolean flag = sp.getBoolean("rememberPassword", false);

		return flag;
	}

}
